package com.liu.yuoj.codesandbox;

import cn.hutool.core.io.resource.ResourceUtil;
import com.liu.yuoj.model.dto.questionsubmit.QuestionSubmitAddRequest;
import com.liu.yuoj.model.entity.User;
import com.liu.yuoj.model.enums.QuestionSubmitLanguageEnum;
import com.liu.yuoj.service.QuestionSubmitService;
import com.liu.yuoj.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;

/**
 * @author 刘渠好
 * @since 2025-04-04 21:48
 */
@SpringBootTest
public class CodeSandBoxDemo {


    @Value ("${codesandbox.type}")
    String type;

    @Resource
    private QuestionSubmitService questionSubmitService;

    @Resource
    private UserService userService;


    @Test
    public void test(HttpServletRequest request) {
        String code = ResourceUtil.readStr ("tempcode/Demo1.java", StandardCharsets.UTF_8);
        QuestionSubmitAddRequest addRequest = new QuestionSubmitAddRequest ();
        addRequest.setCode (code);
        addRequest.setLanguage (QuestionSubmitLanguageEnum.JAVA.getValue ());
        addRequest.setQuestionId (1908400737556512770L);
        User loginUser = userService.getLoginUser (request);
        questionSubmitService.doQuestionSubmit (addRequest,loginUser);
    }
}
